package com.example.m4;

import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
//这个可以加在方法上，这个方法会自动处理消息

public class Consumer {
//    每个rabbitlistener都会注册成为一个消费者
   @RabbitListener(bindings = @QueueBinding(
           value = @Queue, //队列，可以进行详细配置
           exchange = @Exchange(name = "logs" ,declare = "false"),//交换机
           key = {"error"}
   ))
    public void receive(String msg){
       System.out.println("ok:"+msg);
   }
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue, //队列，可以进行详细配置
            exchange = @Exchange(name = "logs" ,declare = "false"),  //交换机,名字是logs，declare = "false"表示不使用重复定义交换机
            key = {"info","warning","error"}

    ))
    public void receive2(String msg){
        System.out.println("ok-2:"+msg);
    }

}
